Purpose
The replace task is used to replace a string with another string. The replacement can be a specified character, or a regular expression (RegExp), from the original string. A RegExp is a sequence of characters that forms a search pattern. Read more about RegExp here.
Potential Use Case
Suppose you have a list of emails and you need to replace a specific email address with a new updated email address. Using the replace task will find the matching occurrence of the old email and replace it with the new one.
Properties
Input and output parameters are shown below.
Incoming | Type | Description |
---|---|---|
str |
string | Required. The string that contains the value or regular expression to be replaced. |
substrt |
string | Required. A value or pattern within str to search for and be replaced by newSubStr when matched. |
newSubstr |
string | Required. The string that replaces the substr parameter. |
Outgoing | Type | Description |
---|---|---|
replacedString |
string | A new string where the substr has been matched and replaced by the newSubstr . |
Examples
Example 1
In this IAP example, the Reference variable for str
is "Hello World" and the substr
to look for and replace is the word "Hello". The Reference variable for the newSubstr
is the replacement word "Howdy".
The task will replace the word "Hello" with the word "Howdy" and the result that returns will be "Howdy World".
Example 2
In this example the substr
contains a regular expression. The RegExp pattern to match will be /[eo]/g.
The letters "e" and "o" in the str
variable were replaced with the number "1" from the newSubstr
variable. The new replacedString
variable that returns is "H1ll1 W1rld".